package com.slingshot.identitysdk.provider;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;

import java.io.File;

/**
 * created by liushuai on 2018/11/9
 */
public class DGKJChargeFileProvider extends FileProvider {

    public static final String AUTHORITY = "com.slingshot.identitysdk.fileprovider";

    public static Uri getUriFromFile(Context context, File file) {
        return getUriForFile(context, AUTHORITY, file);
    }

    public static Uri compatUriFromFile(Context context, File file, Intent intent) {
        if (!needUseProvider()) {
            return Uri.fromFile(file);
        }

        if (intent != null) {
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        }

        return getUriFromFile(context, file);
    }

    public static boolean needUseProvider() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
    }

}
